/***************************************************************************
 *   Copyright (C) 2007 by Warren Kenny   *
 *   warren.kenny@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <otaMySQLCommonHeader.h>

otaMySQLCommonHeader::otaMySQLCommonHeader()
{
}

otaMySQLCommonHeader::otaMySQLCommonHeader( unsigned int bodyLength, unsigned int sequenceNumber )
: m_bodyLength( bodyLength ),
  m_sequenceNumber( sequenceNumber )
{
}
	
bool otaMySQLCommonHeader::deserialize( const char *data, const unsigned int dataSize, const unsigned int offset, unsigned int &newOffset )
{
	if( dataSize - offset >= OTA_MYSQL_COMMON_HEADER_LENGTH )
	{
		unsigned char length0, length1, length2, sequenceNumber;
		
		bool ok = (	otaBytePacker::removeBasicType( data, dataSize, offset, newOffset, length0 ) &&
				otaBytePacker::removeBasicType( data, dataSize, newOffset, newOffset, length1 ) &&
				otaBytePacker::removeBasicType( data, dataSize, newOffset, newOffset, length2 ) &&
				otaBytePacker::removeBasicType( data, dataSize, newOffset, newOffset, sequenceNumber ) );
		
		m_bodyLength = (((unsigned int) length0) + (((unsigned int) length1) << 8) + (((unsigned int) length2) << 16));
		m_sequenceNumber = (unsigned int) sequenceNumber;
	}
	else
	{
		return false;
	}
}
	
bool otaMySQLCommonHeader::serialize( char *data, const unsigned int dataSize, const unsigned int offset, unsigned int &newOffset )
{
	if( dataSize - offset >= OTA_MYSQL_COMMON_HEADER_LENGTH )
	{
		return true;	
	}
	else
	{
		return false;
	}
}
	
unsigned int otaMySQLCommonHeader::getBodyLength()
{
	return m_bodyLength;
}
	
unsigned int otaMySQLCommonHeader::getSequenceNumber()
{
	return m_sequenceNumber;
}


otaMySQLCommonHeader::~otaMySQLCommonHeader()
{
}


